<?php
/**
 * demo - modal popup form and send datas by XHR
 *
 * @author Sven Ruttloff, www.sruttloff.de <service@sruttloff.de>
 * @copyright Kombitel OhG
 */

/**
 * this constant defines the document root
 */
if (!defined('DOCROOT'))
define('DOCROOT', dirname(dirname(__FILE__)) . '/');
define('CMSR_PATH_BASEDIR', DOCROOT);
define('CMSR_PATH_BASEDIR_SERVER', DOCROOT);
define('WRITEABLEADMINDIR', '/lib/writeable/');

/**
 * PHP5 autoload function for classes
 *
 * @param string class name
 * @return bool
 */
function __autoload($object) {
    $file = CMSR_PATH_BASEDIR_SERVER . '/phpmy/class/' . strtolower($object) . '.class.php';
    if (!include_once (CMSR_PATH_BASEDIR_SERVER . '/phpmy/class/' . strtolower($object) . '.class.php'))
       include_once (CMSR_PATH_BASEDIR_SERVER . '/lib/class/' . strtolower($object) . '.class.php');
    return true;
}

/**
 * load std function lib
 */
require_once (DOCROOT . 'phpmy/function/standard.inc.php');
require_once (DOCROOT . 'phpmy/function/formelements.inc.php');

// called from Backend
$frontend = frontend::getInstance();
$i18n = new i18n('DE');
$frontend->setI18n($i18n);

DEFINE('ASCGRAPH', '<div class="sortdirectionup" style="" title="' . $i18n->Translate('Ascending') . '"></div>');
DEFINE('DESCGRAPH', '<div class="sortdirectiondn" style="" title="' . $i18n->Translate('Descending') . '"></div>');
DEFINE('REQUIREDGRAPH', '<img src="style/image/icon_cross.png" border="0" />');
DEFINE('OKAY', '<img src="style/css/image/apply.png" border="0" />');
DEFINE('MSGHEADOKAY', 'okay');
DEFINE('FAIL', '<img src="style/css/image/messagebox_critical.png" border="0" />');
DEFINE('MSGHEADFAIL', $i18n->Translate('Fehler!'));

switch (sendvar('p'))
{
    case 'xhr' :
    case 'ajax' :
        $xhr = xhranswer::getInstance();
        switch ($_GET['s'])
        {
            default:
                $xhr->setMsg (FAIL . $i18n->Translate('Kein PHP Code ausgeführt'), MSGHEADFAIL);
                break;
        }
        die ($xhr);
        break;
        default :
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" href="style/css/reset/reset-min.css" media="all" />
        <link rel="stylesheet" type="text/css" href="style/css/reset/reset-fonts.css" media="all" />
        <link rel="stylesheet" type="text/css" href="style/css/page.css" media="all" />
        <link rel="stylesheet" type="text/css" href="../phpmy/style/css/mvc.css" media="all" />
        <link rel="stylesheet" type="text/css" href="style/css/form.css" media="all" />
        <link rel="stylesheet" type="text/css" href="../phpmy/style/css/topmenu.css" media="all" />
        <title>PHP meet YUI - Demo</title>
        <script type="text/javascript">
            <!--
            // Base path to phpmy folder
            var PHPmYBaseUrl = BaseUrl = '../phpmy/';


            /* can be called when a link is clicked */
            function _body_onunload(){
                return;
            }

            /**
             * function is called when all external scripts are loaded
             */
            function jsReady(){
                // if you need to init some - do here
                initfillwithdialog();
                return;
            }

            -->
        </script>
        <script type="text/javascript" src="../phpmy/js/yui/build/yuiloader/yuiloader-min.js">
        </script>
        <script type="text/javascript" src="../phpmy/js/loader.js">
        </script>
    </head>
<body onload="" class="yui-skin-sam">
Some Content - <a href="#" onclick="popUpFillWith('lastname', 99);return false;">Click me</a>

<div id="changefillwith">
    <div class="hd">Some Element</div>
    <div class="bd">
        <form method="POST" name="typeform" id="typeform" action="">
            <input type="hidden" name="id" value="" />

            <label for="filltype">some select:</label>
                <select id="filltype" tabindex="19" name="filltype">
                    <option value="ifsexmale">ifsexmale</option>
                    <option value="ifsexfemale">ifsexfemale</option>
                    <option value="firstname">firstname</option>
                    <option value="lastname">lastname</option>

                    <option value="email">email</option>
                    <option value="street">street</option>
                    <option value="housenumber">housenumber</option>
                    <option value="street_housenumber">street_housenumber</option>
                    <option value="zip">zip</option>
                    <option value="city">city</option>

                    <option value="sendasis">sendasis</option>
                    <option value="ignore">ignore</option>
                </select>


            <div class="clear"></div>

        </form>
    </div>

</div>

<script type="text/javascript">
    // init dialog
    var popup1;
    function initfillwithdialog() {
        var tmp = ['Okay', 'Cancel'];
        popup1 = phpmyPopUpModalForm('changefillwith', '?p=xhr&job=changefillwith', '300px', true, tmp);
    }
    function popUpFillWith (id, mvalue) {
        // preselect field
        var sel = document.typeform.filltype;
        for (i = 0; i < sel.length; i++)
            if (sel.options[i].value == mvalue) {
                sel.options[i].selected = true;
            }
        // set id
        document.typeform.id.value = id;
        popup1.show();
    }
</script>
</body>
</html>

<?php
            break;
        break;
}